import random

def monte_carlo_integral(N):
    total = 0
    for _ in range(N):
        x = random.random()  # [0,1) 随机数
        total += x ** 2
    return total / N

print(monte_carlo_integral(1000000))  # 接近 0.333...